<template>
  <div>
    <TopManu @setNurseLevel="setNurseLevel" @setFood="setFood" @setzhenduan="setzhenduan" @setbiangeng="setbiangeng"
      @setchangyong="setchangyong" @setchangkey="setchangkey" @handleNurse="handleNurse"
      @handelDropdown2="handelDropdown2"></TopManu>
    <div class="box">
      <el-col :span="span1">
        <el-form :inline="true" class="demo-form-inline" v-model="formInline">
          <el-form-item label="搜索">
            <el-input placeholder="请输入姓名/门诊号/身份证号" v-model="formInline.rightKeyValue" clearable @change="radiochang"
              size="small">
              <el-button type="success" slot="append" icon="el-icon-search" @click="radiochang">
                查询
              </el-button>
              <el-button type="success" slot="append" @click="shouqi">
                {{ this.span1 == 6 ? "收起" : "展开" }}
              </el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="当天入院">
            <el-checkbox v-model="formInline.today" @change="radiochang"></el-checkbox>
          </el-form-item>
          <el-form-item label="新医嘱">
            <el-radio-group v-model="formInline.is_new_advice" @change="radiochang" size="small">
              <el-radio label=""> 全部</el-radio>
              <el-radio label="1"> 新医嘱</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="医嘱顺序">
            <el-radio-group v-model="formInline.order_by" @change="radiochang" size="small">
              <el-radio label="1"> 床位正序 </el-radio>
              <el-radio label="2"> 床位倒序 </el-radio>
              <el-radio label="3"> 入院时间正序 </el-radio>
              <el-radio label="4"> 入院时间倒序 </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="类型">
            <el-select v-model="formInline.rightRadio" @change="radiochang" multiple placeholder="类型" size="small">
              <el-option v-for="item in Radiooptions" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="范围">
            <el-radio-group v-model="formInline.range" @change="radiochang" size="small">
              <el-radio v-for="item in Radiooptions2" :key="item.value" :label="item.value">
                {{ item.label }}
              </el-radio>
              <!-- <el-radio label="线上品牌商赞助"></el-radio>

              <el-radio label="线下场地免费"></el-radio> -->
            </el-radio-group>
          </el-form-item>
          <el-form-item label="病区">
            <el-select v-model="formInline.icu_id" @change="radiochang" placeholder="病区" width="300" size="small">
              <el-option label="全部" value=""> </el-option>
              <el-option v-for="item in getBuildlist" :key="item.value" :label="item.name" :value="item.id">
                <span style="float: left">{{ item.name }}</span>
                <span style="float: right; color: #8492a6; font-size: 14px">占 {{ item.full_bed_count }}</span>
                <span style="float: right; color: #8492a6; font-size: 14px">空 {{ item.empty_bed_count }}</span>
              </el-option>
            </el-select>
          </el-form-item>
          <div class="pen_count">
            <div>
              当前人数：<span>{{ data_info.member_count }}人</span>
            </div>
            <div>
              欠费人数：<span>{{ data_info.no_money }}人</span>
            </div>
          </div>
        </el-form>
        <el-table :data="patientlist" :row-class-name="tableRowClassName" border style="width: 100%"
          @row-click="rowClick" :highlight-current-row="false">
          <el-table-column type="index" width="40"> </el-table-column>
          <el-table-column prop="room_name" :show-overflow-tooltip="true" width="60" label="床号">
            <template slot-scope="scope">
              {{ scope.row.room_info[3] }}
            </template>

            <!-- </template> -->
          </el-table-column>

          <el-table-column prop="status" width="70" label="状态">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status == 1 || scope.row.status == 0">待入院</el-tag>
              <el-tag v-if="scope.row.status == 2" type="success">在院</el-tag>
              <el-tag v-if="scope.row.status == 3" type="warning">申请出院</el-tag>
              <el-tag v-if="scope.row.status == 4" type="info">待出院</el-tag>
              <el-tag v-if="scope.row.status == 5" type="danger">已出院</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="member.name" label="姓名" width="70">
          </el-table-column>
          <!-- <el-table-column prop="member.psn_no" width="250" label="人员编号">
          </el-table-column> -->
          <el-table-column prop="member.gender" label="性别" width="30">
          </el-table-column>
          <el-table-column prop="age" label="年龄" width="40">
          </el-table-column>

          <el-table-column prop="doctor.real_name" label="主治医生">
          </el-table-column>
        </el-table>
        <el-pagination background style="float: right" @size-change="handleSizeChange" :current-page="formInline.page"
          :page-sizes="[10, 20, 30, 100]" :page-size="formInline.limit"
          layout="sizes , total , prev, pager, next , jumper" @current-change="handlePagination" :total="total">
        </el-pagination>
      </el-col>
      <el-col :span="span2">
        <el-col :span="24" style="margin-bottom: 5px">
          <el-card class="box-card" style="padding: 5px">
            <infocrad :id="id"></infocrad>
          </el-card>
        </el-col>

        <el-col :span="24">
          <el-card class="box-card" style="padding: 5px">
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="医嘱记录" name="first">
                <el-form ref="form" label-width="10px">
                  <el-col :span="7">
                    <el-form-item label="">
                      <el-radio-group v-model="tabIndex" @change="resdes" placeholder="请选择期效">
                        <el-radio-button size="small" label="1">长期</el-radio-button>
                        <el-radio-button size="small" label="2">临时</el-radio-button>
                      </el-radio-group>

                      <el-button plain @click="drawer2 = true">开立</el-button>
                      <el-button @click="printAdvice">打印医嘱单</el-button>

                    </el-form-item>
                  </el-col>
                  <el-col :span="3">
                    <el-form-item label="">
                      <el-input v-model="keyword" placeholder="关键字"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="3">
                    <el-form-item label="">
                      <el-select v-model="advice_type" @change="resdes" placeholder="类型">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="项目" value="1"></el-option>
                        <el-option label="药品" value="2"></el-option>
                        <el-option label="医嘱" value="3"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>

                  <el-col :span="3">
                    <el-form-item label="">
                      <el-select v-model="statusIndex" @change="resdes" multiple placeholder="状态">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="草稿" value="1"></el-option>
                        <el-option label="提交" value="2"></el-option>
                        <el-option label="校对" value="3"></el-option>
                        <el-option label="完成" value="4"></el-option>
                        <el-option label="待停止" value="5"></el-option>
                        <el-option label="已停止" value="6"></el-option>
                        <el-option label="废除" value="7"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="">
                      <el-date-picker v-model="datatime" @change="resdes" type="date" placeholder="选择日期"
                        format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <!-- <el-col :span="3">
                    <el-button
                      type="success"
                      style="float: right"
                      @click="onSubmit"
                      >搜索</el-button
                    >
                  </el-col>  -->
                </el-form>
                <el-col :span="3">
                  <!-- <el-button plain @click="canceldialogdeposit = true"
                    >开立</el-button
                  >   -->

                  <div class="right-tabs2">
                    <div @mousemove="showColor = true" @mouseleave="showColor = false">
                      说明
                      <ul class="right-tabs-flex2" v-if="showColor">
                        <li>草稿</li>
                        <li>提交</li>
                        <li>校对</li>
                        <li>完成</li>
                        <li>待停止</li>
                        <li>已停止</li>
                        <li>废除</li>
                      </ul>
                    </div>
                  </div>
                </el-col>
                <el-col :span="24">
                  <el-button plain @click="handleCommand('t')">提交</el-button>
                  <el-button plain @click="handleCommand('cx')">撤销提交
                  </el-button>
                  <el-button plain @click="handleCommand('fc')">医嘱作废
                  </el-button>
                  <el-button plain @click="handleCommand('tz')">停止</el-button>
                  <el-button plain @click="handleCommand('cxtz')">撤销停止
                  </el-button>
                  <el-button plain @click="handleCommand('d')">删除</el-button>
                  <el-button @click="handleCommand('tjcy')">保存为常用</el-button>
                  <el-button @click="printChufang">打印处方</el-button>
                </el-col>
                <!-- highlight-current-row -->
                <el-table :data="tableData" style="width: 100%" border height="70vh" :row-class-name="tableRowClassName"
                  :span-method="objectSpanMethod" :highlight-current-row="true"
                  @selection-change="handleSelectionChange">
                  <el-table-column type="selection" width="40">
                  </el-table-column>
                  <template v-for="(item, index) in tableTitle1">
                    <el-table-column v-if="item.prop == 'id'" :width="item.width" :prop="item.prop" :fixed="item.left"
                      :label="item.label" :key="index" :sortable="item.sortable" :show-overflow-tooltip="true">
                      <template slot-scope="scope">
                        <span>
                          {{ scope.$index + 1 }}
                        </span>
                      </template>
                    </el-table-column>
                    <el-table-column v-else :width="item.width" :prop="item.prop" :fixed="item.left" :label="item.label"
                      :key="index">
                    </el-table-column>
                  </template>
                  <el-table-column fixed="right" label="操作" width="50">
                    <template slot-scope="scope">
                      <el-button @click="xiugai(scope.row)" type="text" size="small" v-if="scope.row.status === '草稿'">
                        修改
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
                <el-drawer title="开立医嘱" :visible.sync="drawer2" direction="btt" :modal-append-to-body="false"
                  :close-on-press-escape="false" :wrapperClosable="false" :modal="false" size="65%">
                  <el-col :span="24">
                    <kailiyizhu :selectParams="selectParams" ref="rightCZ" :thatF="this" :selectData="selectData"
                      :id="id" :multip="multipleSelection" @getDrugItem="getDrugItem()"
                      @getServiceItem="getAdviceFeeItem(arguments)" @createAdvice="createAdvice(arguments)">
                    </kailiyizhu>
                  </el-col>
                  <el-button style="float: right; margin-top: 5px; margin-right: 10px" type="success"
                    @click="cancelHospital">保 存</el-button>
                  <el-button style="float: right; margin-top: 5px; margin-right: 10px" @click="drawer2 = false">取 消
                  </el-button>
                </el-drawer>
              </el-tab-pane>
              <el-tab-pane label="病历查询" name="second">
                <el-button @click="binglilogdeposit = true">新增</el-button>
                <!-- <el-button @click="chakanjiu">旧病历</el-button> -->
                <!-- <el-empty description="暂无数据"  ></el-empty> -->

                <el-row :gutter="12">
                  <el-col :span="12" v-for="(item, index) in binglilist" :key="index">
                    <el-card shadow="always">
                      <el-row>
                        <el-col :span="6">
                          <img src="@/assets/bingli.png" alt="" width="100px" />
                        </el-col>
                        <el-col :span="14">
                          <h3>
                            {{ item.tpl_name }}
                            <span style="float: right">{{
                                item.tpl_type == 1
                                  ? item.is_new == 1
                                    ? "旧"
                                    : "新"
                                  : "PDF"
                            }}</span>
                          </h3>
                          <span>查看时间:{{ item.save_time }}</span>
                        </el-col>
                        <el-col :span="4">
                          <el-button style="float: right" type="success" @click="hedachakan(item)">查看
                          </el-button>
                          <el-button style="float: right; margin-top: 20px" type="danger"
                            @click="deleteMemberMeical(item)">删除
                          </el-button>
                        </el-col>
                      </el-row>
                    </el-card>
                  </el-col>
                </el-row>
              </el-tab-pane>
              <!--              <el-tab-pane label="医技报告" name="third" >-->

              <!--                <el-table-->
              <!--                  :data="yijidata"-->

              <!--                  border-->
              <!--                  style="width: 100%"-->

              <!--                  :highlight-current-row='false'-->

              <!--                >-->
              <!--                  <el-table-column type="index" width="40"></el-table-column>-->
              <!--                  <el-table-column prop="business_name" label="检查项">-->
              <!--                  </el-table-column>-->

              <!--                  <el-table-column prop="yj_execution_time" label="检查时间"></el-table-column>-->
              <!--                  -->
              <!--                  <el-table-column prop="amount" label="检查费"></el-table-column>-->
              <!--                  <el-table-column prop="check_result" label="检查结果"></el-table-column>-->

              <!--                  <el-table-column prop="yj_username" label="检查医生">-->
              <!--                  </el-table-column>-->

              <!--                </el-table>-->

              <!--              </el-tab-pane>-->
            </el-tabs>
          </el-card>
        </el-col>
      </el-col>
      <el-drawer title="" :visible.sync="drawer" :with-header="false">
        <el-card class="box-card" style="margin-left: 20px; min-height: 700px">
          <el-tabs v-model="activeName2" @tab-click="handleClick2">
            <el-tab-pane label="执行记录" name="first">
              <exect :id="id"></exect>
            </el-tab-pane>
            <el-tab-pane label="费用记录" name="third">
              <costRecord :id="id"></costRecord>
            </el-tab-pane>
            <el-tab-pane label="变更记录" name="second">
              <record :id="id"></record>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-drawer>

      <el-dialog :fullscreen="true" :close-on-click-modal="false" :title="yizhutitle"
        :visible.sync="canceldialogdeposit">
        <el-col :span="24">
          <infocrad :id="id" ref="userinfn"></infocrad>
        </el-col>
        <viewTitle text="医嘱信息" style="font-size: 20px; margin-bottom: 20px" />
        <el-col :span="24">
          <kailiyizhu :selectParams="selectParams" ref="rightCZ" :thatF="this" :selectData="selectData" :id="id"
            :multip="multipleSelection" @getDrugItem="getDrugItem()" @getServiceItem="getAdviceFeeItem(arguments)"
            @createAdvice="createAdvice(arguments)"></kailiyizhu>
        </el-col>
        <div slot="footer" class="dialog-footer">
          <el-button @click="canceldialogdeposit = false">取 消</el-button>
          <el-button type="success" @click="cancelHospital">保 存</el-button>
        </div>
      </el-dialog>
      <el-dialog :fullscreen="true" :close-on-click-modal="false" title="常用医嘱" :visible.sync="changyonglog">
        <viewTitle text="常用医嘱" style="font-size: 20px; margin-bottom: 20px" />
        <el-col :span="24">
          <logging ref="logging2" />
        </el-col>
        <div slot="footer" class="dialog-footer">
          <el-button @click="changyonglog = false">取 消</el-button>
        </div>
      </el-dialog>
      <!-- 护理等级 -->
      <el-dialog :close-on-click-modal="false" title="护理等级" :visible.sync="NurseLeveldialogdeposit" width="70%">
        <el-col :span="24">
          <infocrad :id="id" ref="userinfn"></infocrad>
        </el-col>

        <el-col :span="24">
          <el-form>
            <el-form-item label="护理等级">
              <el-select v-model="nlevelinfo.pid" placeholder="护理等级">
                <el-option v-for="(item, index) in huli" :key="index" :label="item.name" :value="item.id">{{ item.name
                }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <div slot="footer" class="dialog-footer">
          <el-button @click="NurseLeveldialogdeposit = false">取 消</el-button>
          <el-button type="success" @click="levelHospital">保 存</el-button>
        </div>
      </el-dialog>
      <!-- 饮食种类 -->
      <el-dialog :close-on-click-modal="false" title="饮食种类" :visible.sync="fooddialogdeposit" width="70%">
        <el-col :span="24">
          <infocrad :id="id" ref="userinfn"></infocrad>
        </el-col>

        <el-col :span="24">
          <el-form>
            <el-form-item label="饮食种类">
              <el-select v-model="foodinfo.pid" placeholder="饮食种类">
                <el-option v-for="(item, index) in yinshi" :key="index" :label="item.name" :value="item.id">{{ item.name
                }}
                </el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <div slot="footer" class="dialog-footer">
          <el-button @click="fooddialogdeposit = false">取 消</el-button>
          <el-button type="success" @click="foodHospital">保 存</el-button>
        </div>
      </el-dialog>
      <!-- 诊断维护 -->
      <el-dialog :fullscreen="true" :close-on-click-modal="false" title="诊断维护" :visible.sync="zhenduanlogdeposit"
        width="70%">
        <el-col :span="24">
          <infocrad :id="id" ref="userinfn"></infocrad>
        </el-col>

        <el-col :span="24">
          <zhenduan :selectParams2="selectParams2" ref="rightZD" :selectData2="selectData2" :id2="id"
            :dtime="patientinfo.begntime" @getDiseaseDict="getDiseaseDict()" @getDiseaseDict2="getDiseaseDict2()"
            @createAdvice2="createAdvice2(arguments)"></zhenduan>
        </el-col>
        <div slot="footer" class="dialog-footer">
          <el-button @click="zhenduanlogdeposit = false">取 消</el-button>
          <el-button type="success" @click="zhenduanHospital">保 存</el-button>
        </div>
      </el-dialog>
      <el-dialog :fullscreen="true" :close-on-click-modal="false" title="选择模板" :visible.sync="binglilogdeposit"
        :before-close="closehistep">
        <el-col :span="24">
          <caselist :id="id" @opencompile="opencaselist"></caselist>
        </el-col>
        <div slot="footer" class="dialog-footer">
          <el-button @click="binglilogdeposit = false">取 消</el-button>
        </div>
      </el-dialog>
      <el-dialog :close-on-click-modal="false" title="选择模板" :visible.sync="changyonglogdeposit" width="50%">
        <el-col :span="24">
          <el-form>
            <el-form-item label="标题">
              <el-input v-model="changyong.title" size="mini" placeholder="常用医嘱标题"></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input v-model="changyong.remark" size="mini" placeholder="常用医嘱备注"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <div slot="footer" class="dialog-footer">
          <el-button @click="changyonglogdeposit = false">取 消</el-button>
          <el-button @click="changyonghead()">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog :close-on-click-modal="false" title="修改医嘱" :visible.sync="yizhudeposit">
        <el-form :inline="true" :model="dialogForm" label-width="auto">
          <el-form-item label="医嘱内容">
            {{ dialogForm.business_name }}
          </el-form-item>

          <el-form-item label="开立时间">
            <input type="datetime-local" style="width: 150" step="01" v-model="dialogForm.start_time" />
          </el-form-item>
          <el-form-item label="数量">
            <el-input v-model="dialogForm.count" placeholder="总量"></el-input>
            {{ dialogForm.base_unit }}
          </el-form-item>
          <el-form-item label="剂量">
            <el-input v-model="dialogForm.dose" placeholder="剂量"></el-input>
          </el-form-item>
          {{ dialogForm.dose_unit }}
          <el-form-item label="频次">
            <el-select v-model="dialogForm.each_dos" placeholder="频次">
              <el-option v-for="item in pinci" :key="item.name" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="用法">
            <el-select v-model="dialogForm.usage" placeholder="用法">
              <el-option v-for="item in geiyao" :key="item.name" :label="item.name" :value="item.name">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="皮试">
            <el-checkbox v-model="dialogForm.is_skin_test"></el-checkbox>
          </el-form-item>

          <el-form-item label="备注">
            <el-input v-model="dialogForm.remark" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="yizhudeposit = false">取 消</el-button>
          <el-button type="success" @click="xiugaiup">确 定</el-button>
        </div>
      </el-dialog>
      <el-dialog :fullscreen="true" :close-on-click-modal="false" :visible.sync="iframeFlag" :before-close="offiframe">
        <span>
          <iframeDemo :url="orurl" ref="iframeDemo" height="800px" />
        </span>
      </el-dialog>
      <el-dialog :close-on-click-modal="false" center title="确认时间" :visible.sync="tingzhilogdeposit" width="30%">
        <el-col :span="12">
          <div class="block">
            <input type="datetime-local" step="01" v-model="stop_time" />
          </div>
        </el-col>
        <el-col :span="12">
          <h3 class="block">当前操作员：{{ real_name }}</h3>
        </el-col>
        <div slot="footer" class="dialog-footer" style="margintop: 30px">
          <el-button @click="tingzhilogdeposit = false">取 消</el-button>
          <el-button type="success" @click="doctorStopAdvice">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog :fullscreen="true" :close-on-click-modal="false" title="打印医嘱单" :visible.sync="yizhudataVisible1">
        <yizhudan @reload="reload" v-if="tabIndex == '1'" :yizhudata="yizhudata" :type="tabIndex" />
        <linyizhudan @reload="reload" v-else-if="tabIndex == '2'" :yizhudata="yizhudata" :type="tabIndex" />
        <div slot="footer" class="dialog-footer">
          <el-button @click="yizhudataVisible1 = false">取 消</el-button>
        </div>
      </el-dialog>

      <el-dialog :fullscreen="true" :close-on-click-modal="false" title="分床" :visible.sync="dialogFormVisible1">
        <infocradNurse :id="id"></infocradNurse>
        <Splitbed ref="splitbed" :patientinfo="patientinfo" @splitbed="splitbed(arguments)" />
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible1 = false">取 消</el-button>
          <el-button type="primary" @click="handelMemberSave">保 存</el-button>
        </div>
      </el-dialog>

      <el-dialog :close-on-click-modal="false" title="住院医生核算表" center :visible.sync="shoujulogdeposit3">
        <el-form>
          <el-form-item label="类型">
            <el-select v-model="rightRadio" multiple placeholder="类型" size="small">
              <el-option v-for="(item, index) in Radiooptions" v-show="index != 0" :key="index" :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="开始日期">
            <el-date-picker type="date" placeholder="选择日期" v-model="start_time2" style="width: 100%"
              format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
          <el-form-item label="结束日期">
            <el-date-picker type="date" placeholder="选择日期" v-model="end_time2" style="width: 100%"
              format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="padding: 0px; margin: 5px">
          <el-button @click="shoujulogdeposit3 = false">取 消</el-button>
          <el-button type="success" @click="exportHospitalDoctorInfo">确定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import ViewTitle from "@/forComponents/viewTitle";
import TopManu from "@/components/TopMenu";

import {
  getNurseLevel,
  getAdviceList,
  getAdviceDrug,
  createAdvice,
  doctorStopAdvice,
  deleteAdvice,
  updateAdviceStatus,
  setNurseLevel,
  toVoidAdvice,
  setFood,
  getAdviceFee,
  saveDiagonsis,
  updateAdvice,
  getMemberMedicalList,
  deleteMemberMeical,
  getAllIcu,
  getMyMedicalSkill,
  shuyugetList,
  getHospitalMember,
  collectAdvice,
  getCollectAdvice,
  printAdvice,
  getMemberMedicalList2,
  exportHospitalDoctorInfo,
  distributeBed,
} from "@/api/zhuyanre";
import { getdictIndex, getgetDiseaseDict } from "@/api/register";
import { getServiceGroup, getServiceGroupDetail } from "@/api/dataDictionaries";
import { readHospitalMemberDetail } from "@/api/zhuyanre";
import { getOrganization } from "@/api/organization";
import kailiyizhu from "../components/kailiyizhu.vue";
import zhenduan from "../components/zhenduan.vue";
import logging from "../components/logging.vue";
import exect from "./compon/Execution.vue";
import record from "./compon/record.vue";
import costRecord from "./compon/costRecord.vue";
import infocrad from "../../hospitalizedCharge/components/infocrad.vue";
import infocradNurse from "../../hospitalNurse/components/infocrad.vue";
import Splitbed from "../../hospitalNurse/components/Splitbed.vue";
import caselist from "./compon/caseList/index.vue";
import compile from "./compile/index.vue";
import iframeDemo from "@/components/iframeDemo/index.vue";
import { iframeUrl, http2, http } from "@/utils/server.js";
import yizhudan from "./compon/yizhudan备份1.vue";
import linyizhudan from "./compon/linyizhudan.vue";
import data from "../../../bai/data";
var that;
export default {
  name: "hospitaldetails",
  data() {
    return {
      end_time2: "",
      start_time2: "",
      shoujulogdeposit3: false,
      orurl: `${iframeUrl}/#/caselist2?type=3`,

      id: "",

      iframeFlag: false,
      showColor: false,
      changyonglog: false,
      drawer2: false,
      tingzhilogdeposit: false,
      yizhudataVisible1: false,
      yizhudata: [],
      stop_time: "",
      yizhutitle: "开立医嘱",
      activeName: "first",
      activeName2: "first",
      canceldialogdeposit: false,
      NurseLeveldialogdeposit: false,
      binglilogdeposit: false,
      tableData: [],
      reload: "",
      nlevelinfo: {
        id: "",
        pid: "",
      },
      dialogForm: {
        used_frqu: {},
      },
      rightRadio: [], //核算
      formInline: {
        rightKeyValue: "",
        rightRadio: ["2"],
        range: "3",
        today: false,
        page: 1,
        limit: 10,
        icu_id: "",
        nature: "",
        is_new_advice: "",
        order_by: "1",
      },
      data_info: {},
      Radiooptions: [
        {
          value: "1",
          label: "待入院",
        },
        {
          value: "2",
          label: "在院",
        },
        {
          value: "3",
          label: "申请出院",
        },
        {
          value: "4",
          label: "待出院",
        },
        {
          value: "5",
          label: "已出院",
        },
      ],
      Radiooptions2: [
        {
          value: "1",
          label: "个人",
        },
        {
          value: "2",
          label: "科室",
        },
        { value: "3", label: "全院" },
      ],
      total: 0,
      statusIndex: [],
      advice_type: "",
      datatime: "",
      tableTitle1: [
        {
          prop: "id2",
          left: "left",
          label: "成组",
          width: "50",
        },
        {
          prop: "id",
          left: "left",
          label: "序号",
          width: "50",
          sortable: true,
        },

        // {
        //   prop: "source",
        //   label: "来源",
        // },
        // {
        //   prop: "advice_type",
        //   label: "医嘱项类型",
        //   width: "100",
        // },
        // '1西药2中药3检验4检查5手术6治疗'

        {
          prop: "typename",
          label: "医嘱类型",

          width: "80",
        },
        {
          prop: "start_time",
          label: "开始时间",
          left: "left",
          width: "180",
        },
        {
          prop: "business_name",
          label: "医嘱内容",
          width: "180",
          left: "left",
        },

        {
          prop: "remark",
          label: "开立备注",
          showtooltip: "true",
          width: "180",
        },
        {
          prop: "dose_unit2",
          label: "一次剂量",
          width: "100",
        },
        // {
        //   prop: "dose_unit",
        //   label: "剂量单位",
        //   width: "50",
        // },
        {
          prop: "usage",
          label: "用药方式",
          width: "80",
        },
        {
          prop: "used_frqu.name",
          label: "用药频次",
          width: "100",
        },

        {
          prop: "specification",
          label: "规格",
          width: "110",
        },
        {
          prop: "status",
          label: "医嘱状态",
          width: "80",
        },

        {
          prop: "number2",
          label: "用量",
          width: "80",
        },

        {
          prop: "execution_num",
          label: "执行次数",
        },
        {
          prop: "execution_time",
          label: "执行时间",
          type: 1,
          width: 160,
        },
        {
          prop: "execution_user_name",
          label: "执行人",
          // type: 1,
        },
        {
          prop: "advice_doctor_name",
          label: "医嘱医生",
        },
        {
          prop: "refund_num",
          label: "退费次数",
        },

        {
          prop: "end_time",
          label: "医生停止时间",
          width: "180",
        },
        {
          prop: "stop_doctor_name",
          label: "停止医生",
        },
        {
          prop: "stop_time",
          label: "护士停止时间",
          width: "180",
        },

        {
          prop: "stop_nurse_name",
          label: "停止护士",
        },

        // {
        //   prop: "total",
        //   label: "总价",
        // },

        // {
        //   prop: "skin_test",
        //   label: "皮试",
        // },
        {
          prop: "result2",
          label: "皮试结果",
        },

        // {
        //   prop: "drip_speed",
        //   label: "滴速",
        // },

        // {
        //   prop: "department_name2",
        //   label: "执行部门",

        // },

        // {
        //   prop: "jiaozhu",
        //   label: "西药脚注",

        // },
        {
          prop: "price",
          label: "单价",
        },
        {
          prop: "yb_code",
          label: "目录编码",
          width: "220",
        },
        // {
        //   prop: "num",
        //   label: "库存数量",
        // },
      ],
      drawer: false,
      selectParams: {
        keyword: "",
        page: 1,
        limit: 5,
        pageCount: 0,
      },
      //诊断
      selectParams2: {
        keyword: "",
        keyword2: "",
        page: 1,
        limit: 15,
        pageCount: 0,
        page2: 1,
        limit2: 15,
        pageCount2: 0,
      },
      selectData: {
        selectData1: [],
        selectData2: [],
      },
      selectData2: {
        selectData1: [],
      },
      yinshi: [],
      tabIndex: "1",
      disu: [],
      pinci: [],
      geiyao: [],
      xiyaojiaozhu: [],
      id: this.$route.query.id,
      patientinfo: {},
      huli: [],
      keyword: "",
      fooddialogdeposit: false,
      foodinfo: {
        id: "",
        pid: "",
        name: "",
      },
      shoufeitype: [],
      zhenduanlogdeposit: false,
      binglilist: [],
      member_id: "",
      multipleSelection: [],
      departmentoptions: [],
      patientlist: [],
      patientinfo: [],
      danwei: [],
      zhijidanwei: [],
      yizhudeposit: false,
      getBuildlist: [],
      tableHeight: "",
      span1: 6,
      span2: 18,
      jsonData: {},
      changyonglogdeposit: false,
      changyong: {
        title: "",
        remark: "",
        extra_json: "",
      },
      yijidata: [],
      xiangmudanwei: [],
      real_name: "",
      real_id: "",
      getIndex2: 0,
      dialogFormVisible1: false,
    };
  },
  mounted(option) {
    that = this;
    this.tableHeight = document.documentElement.clientHeight - 470;
    this.getHospitalMember();
    this.real_name = JSON.parse(localStorage.getItem("userInfo")).real_name;
    this.real_id = JSON.parse(localStorage.getItem("userInfo")).id;
    this.getDrugItem();

    this.getCommonGetPinci();
    this.getDrug_channelGetList();
    this.getOrganization();
    this.getDict_dataDictIndex();
    this.getNurseLevel();

    this.getDiseaseDict();

    // this.tableRowClassName()
    console.log("000");
    this.getMemberMedicalList();
    this.canceldialogdeposit = true;
    this.canceldialogdeposit = false;
    getAllIcu({ level: "2" }).then((res) => {
      this.getBuildlist = res.data;
    });
  },

  methods: {
    printChufang() {
      let params = {

      }
      console.log('this.multipleSelection',this.multipleSelection)
      let is_data=this.multipleSelection.findIndex(v=>v.advice_type!='药品')
      console.log("is_data",is_data)
      if(is_data!=-1){
        return this.$message({
          message: "请选中需要打印的西药",
          type: "error",
        });
      }

      if (this.multipleSelection.length <= 0) {
        return this.$message({
          message: "请选中需要打印的处方",
          type: "error",
        });
      }
      readHospitalMemberDetail({ id: this.id }).then(res => {
        console.log("res", res)
        if (res.code == 200) {
          params.member = res.data.member;
          params.multipleSelection = this.multipleSelection;
          params.masterInfo = res.data.masterInfo



          const { href } = this.$router.resolve({
            path: "/print/hosPrescription",
            query: { params: JSON.stringify(params) },
          });
          window.open(href, "_blank");
        }
      })


    },
    exportHospitalDoctorInfo() {
      let d3 = {
        start_time: this.start_time2,
        end_time: this.end_time2,
        status: this.rightRadio.toString(),
      };
      that.loading = that.$loading({
        lock: true,
        text: "正在下载中.....",
        background: "rgba(0, 0, 0, 0.7)",
      });
      exportHospitalDoctorInfo(d3).then((res) => {
        if (res.code == 200) {
          that.loading.close();
          window.open(this.$http + "/" + res.data.file_url);
        }
      });
    },
    handelDropdown2() {
      this.shoujulogdeposit3 = true;
    },
    // /保存  分床
    handelMemberSave(arr) {
      this.$refs.splitbed.splitbed();
    },
    // 分床
    splitbed(arr) {
      console.log("分床");
      var data_tt = arr[0];
      distributeBed(data_tt)
        .then((res) => {
          // //  console.log(res);
          if (res.code == 200) {
            this.$message({
              message: "操作成功",
              type: "success",
            });

            this.dialogFormVisible1 = false;
          }
        })
        .catch((e) => { });
    },
    handleNurse(e) {
      if (e == 1) {
        this.dialogFormVisible1 = true;
      }
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.status === "草稿") {
        return "status-1";
      } else if (row.status === "提交") {
        return "status-2";
      } else if (row.status === "校对") {
        return "status-3";
      } else if (row.status === "完成") {
        return "status-4";
      } else if (row.status === "待停止") {
        return "status-5";
      } else if (row.status === "已停止") {
        return "status-6";
      } else if (row.status === "废除") {
        return "status-7";
      }
      if (row.id === this.getIndex2) {
        return "success-row";
      }
      return "";
    },

    opencaselist(item) {
      if (item.is_new == 1) {
        this.binglilogdeposit = false;
        this.iframeFlag = true;
        this.$nextTick(() => {
          this.orurl = `${iframeUrl}/#/caselist2?templateId=${item.id}&id=${this.id
            }&token=${localStorage.getItem("token")}&member_id=${that.patientinfo.member.id
            }&userType=2&ifType=1&tpl_name=${item.name}&category_id=${item.category_id
            }`;
          setTimeout(function () {
            that.$nextTick(function () {
              let json = {
                templateId: item.id,
                id: this.id,
                member_id: that.patientinfo.member.id,
                userType: 2,
                ifType: 1,
                tpl_name: item.name,
                category_id: item.category_id,
              };
              // member_id:this.user.userId,id:this.user.id,type:this.user.type
              this.$refs.iframeDemo.handleEmit(json);
            });
          }, 100);
        });
      } else {
        var http = `${http2}?tepid=${item.id}&is_pattern=2&uid=${this.id}&source=3&his_uid=${this.real_id}&real_name=${this.real_name}&tep_name=${item.name}`;
        window.open(http, "_blank");
      }
    },
    setchangkey(key2) {
      this["_API"]
        .getByKey({ key: key2 })
        .then((res2) => {
          var clinic_use_medical_record_tpl_id = "";
          if (res2.code == 200) {
            if (key2 == "zd_use_medical_record_tpl_id") {
              clinic_use_medical_record_tpl_id =
                res2.data.zd_use_medical_record_tpl_id;
            } else if (key2 == "jcjy_medical_record_tpl_id") {
              clinic_use_medical_record_tpl_id =
                res2.data.jcjy_medical_record_tpl_id;
            } else if (key2 == "bc_medical_record_tpl_id") {
              clinic_use_medical_record_tpl_id =
                res2.data.bc_medical_record_tpl_id;
            } else if (key2 == "jc_medical_record_tpl_id") {
              clinic_use_medical_record_tpl_id =
                res2.data.jc_medical_record_tpl_id;
            }
            var http = `${http2}?tepid=${clinic_use_medical_record_tpl_id}&is_pattern=2&uid=${this.id}&source=3&his_uid=${this.real_id}&real_name=${this.real_name}&tep_name=`;
            window.open(http, "_blank");

            //  loading.close()
          }
        })
        .catch((e) => {
          console.log(e);
        });
    },
    closehistep() {
      this.getMemberMedicalList();
      this.binglilogdeposit = false;
    },
    offiframe() {
      this.iframeFlag = false;
      this.getMemberMedicalList();
    },
    //分页
    handleSizeChange(e) {
      this.formInline.limit = e;
      this.getHospitalMember();
    },
    handlePagination(e) {
      this.formInline.page = e;
      this.getHospitalMember();
    },
    //搜索
    radiochang(val) {
      // console.log(val)
      this.formInline.page = 1;
      this.getHospitalMember();
    },
    rowClick(row, ent, rowIndex) {
      this.getIndex2 = row.id;
      console.log(rowIndex, "00000");
      console.log(" this.patientinfo", this.patientinfo);
      this.patientinfo = row;
      this.id = that.patientinfo.id;
      this.member_id = that.patientinfo.member.id;
      this.getAdviceList(this.id);
      this.getMemberMedicalList();
      this.getMyMedicalSkill();
    },
    handleCurrentChange(e) {
      console.log(e);
      this.getIndex2 = e.id;
    },
    getHospitalMember() {
      let data_t = {
        ipt_no: "",
        m_keyword: that.formInline.rightKeyValue,
        icu_id: that.formInline.icu_id,
        bed: "",
        status: that.formInline.rightRadio.toString(),
        doctor_id: "",
        nurse_id: "",
        dept_id: "",
        nature: that.formInline.nature,
        today: that.formInline.today ? 1 : "",
        range: that.formInline.range,
        page: that.formInline.page,
        limit: that.formInline.limit,
        is_new_advice: that.formInline.is_new_advice,
        order_by: that.formInline.order_by,
        source: "1",
      };
      getHospitalMember(data_t)
        .then((res) => {
          let data = res.data.list;
          that.total = res.data.count;
          that.data_info = res.data;
          that.patientlist = [];
          if (data.length != 0) {
            // data.forEach((item, key) => {
            //   let arr = {
            //     ipt_no: item.ipt_no,
            //     id: item.id,
            //     name: item.member.name,
            //     id_card: item.member.id_card
            //   };
            //   that.tableData.push(arr);
            // });
            that.patientlist = data;

            for (var i in that.patientlist) {
              that.patientlist[i].room_name =
                that.patientlist[i].room_info[2] +
                that.patientlist[i].room_info[3];
              that.patientlist[i].member.gender =
                that.patientlist[i].member.gender == 1
                  ? "男"
                  : that.patientlist[i].member.gender == 2
                    ? "女"
                    : "其他";
            }

            that.patientinfo = data[0];
            this.id = that.patientinfo.id;
            this.getIndex2 = that.patientinfo.id;
            this.member_id = that.patientinfo.member.id;
            this.getAdviceList(this.id);
            this.getMemberMedicalList();
            // that.$refs.userinfn.readHospitalMemberDetail(patientinfo.id)
          }
        })
        .catch((e) => {
          this.$message({
            message: e.message,
            type: "error",
          });
        });
    },
    getOrganization() {
      getOrganization().then((res) => {
        this.departmentoptions = this.deleteChildren(res.data);
      });
    },
    //删除空childern
    deleteChildren(arr) {
      let childs = arr;
      for (let i = childs.length; i--; i > 0) {
        if (childs[i].children) {
          if (childs[i].children.length) {
            this.deleteChildren(childs[i].children);
          } else {
            delete childs[i].children;
          }
        }
      }
      return arr;
    },
    hedachakan(item) {
      console.log(item);
      if (item.tpl_type == 1) {
        if (item.is_new == 1) {
          this.iframeFlag = true;
          this.$nextTick(() => {
            this.orurl = `${iframeUrl}/#/caselist2?templateId=${item.id}&id=${this.id
              }&token=${localStorage.getItem("token")}&member_id=${that.patientinfo.member.id
              }&userType=2&ifType=2&tpl_name=${item.tpl_name}&category_id=${item.tpl_id
              }`;
            // window.open(this.orurl,'_blank');
            // this.orurl=`${iframeUrl}/#/caselist2`
            setTimeout(function () {
              that.$nextTick(function () {
                let json = {
                  templateId: item.id,
                  id: this.id,
                  member_id: that.patientinfo.member.id,
                  userType: 2,
                  ifType: 2,
                  tpl_name: item.tpl_name,
                  category_id: item.tpl_id,
                };
                // member_id:this.user.userId,id:this.user.id,type:this.user.type
                this.$refs.iframeDemo.handleEmit(json);
              });
            }, 100);
          });
        } else {
          var http = `${http2}?tepid=${item.tpl_id}&is_pattern=2&uid=${this.id}&source=1&his_uid=${this.real_id}&real_name=${this.real_name}&tep_name=${item.tpl_name}&cid=${item.id}`;

          window.open(http, "_blank");
        }
      } else {
        // var http='http://127.0.0.1:8848/rkecm/index.html?cid='+item.id+'&is_pattern=2&uid='+this.id+'&source=1&his_uid='+this.real_id+'&real_name='+this.real_name+'&tep_name='+item.tpl_name+'&tepid='+item.tpl_id
        var http = item.file_url;

        window.open(http, "_blank");
      }
    },
    deleteMemberMeical(item) {
      this.$confirm("是否删除", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      }).then(() => {
        deleteMemberMeical({ id: item.id }).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "删除成功",
              type: "success",
            });
            this.getMemberMedicalList();
          } else {
            this.$message(res.message);
          }
        });
      });
    },
    //设置护理等级
    setNurseLevel() {
      that.NurseLeveldialogdeposit = true;
      that.getNurseLevel();
    },

    //获取护理等级
    getNurseLevel() {
      getNurseLevel({}).then((res) => {
        that.huli = res.data;
      });
    },
    //设置护理等级
    levelHospital() {
      var data_t = that.nlevelinfo;
      data_t.id = that.id;
      setNurseLevel(data_t)
        .then((res) => {
          // let data = res.data;
          // console.log(res);
          if (res.code == 200) {
            that.NurseLeveldialogdeposit = false;
          }
        })
        .catch((e) => { });
    },

    resdes() {
      this.getAdviceList(this.id);
    },
    handleSelectionChange(val) {
      console.log("val", val)
      this.multipleSelection = val;
    },
    unique(arr) {
      const res = new Map();
      return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1));
    },
    handleCommand(command) {
      var that = this;
      var arr = [];
      var arr2 = [];
      var if_bian = true;
      if (command != "tjcy") {
        for (var i in this.tableData) {
          for (let t = 0; t < this.multipleSelection.length; t++) {
            console.log(this.multipleSelection[t].is_group);
            if (
              this.multipleSelection[t].is_group != null &&
              this.multipleSelection[t].is_group != 0
            ) {
              if (
                this.tableData[i].is_group == this.multipleSelection[t].is_group
              ) {
                arr2.push(this.tableData[i]);
              }
            }
          }
        }

        this.multipleSelection = this.unique(
          this.multipleSelection.concat(JSON.parse(JSON.stringify(arr2)))
        );
      }
      that.multipleSelection.forEach((res) => {
        arr.push(res.id);
        if (res.status != "草稿") {
          if_bian = false;
        }
      });
      arr = arr.toString();

      switch (command) {
        case "x":
          if (if_bian && that.multipleSelection.length != 0) {
            // this.canceldialogdeposit=true
          } else {
            this.$message({
              message: "只能修改草稿",
            });
          }

          break;
        //删除
        case "d":
          this.$confirm("是否删除", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            deleteAdvice({
              hospital_id: this.id,
              id: arr,
            }).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: "删除成功",
                  type: "success",
                });
                this.getAdviceList(this.id);
              } else {
                this.$message(res.message);
              }
            });
          });
          break;
        case "t":
          this.$confirm("是否确定提交", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            updateAdviceStatus({
              hospital_id: this.id,
              ids: arr,
              action_type: 1,
            }).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: "提交成功",
                  type: "success",
                });
                this.getAdviceList(this.id);
              } else {
                this.$message(res.message);
              }
            });
          });

          break;
        case "cxtz":
          this.$confirm("是否确定撤销停止", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            doctorStopAdvice({
              hospital_id: this.id,
              ids: arr,
              action_type: 2,
            }).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: "撤销成功",
                  type: "success",
                });
                this.getAdviceList(this.id);
              } else {
                this.$message(res.message);
              }
            });
          });
          break;
        case "cx":
          this.$confirm("是否撤销提交医嘱", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            updateAdviceStatus({
              hospital_id: this.id,
              ids: arr,
              action_type: 2,
            }).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: "撤销成功",
                  type: "success",
                });
                this.getAdviceList(this.id);
              } else {
                this.$message(res.message);
              }
            });
          });
          break;
        case "tz":
          let date = new Date();
          let yyyy = date.getFullYear();
          let MM =
            date.getMonth() + 1 < 10
              ? "0" + (date.getMonth() + 1)
              : date.getMonth() + 1;
          let dd = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
          let HH =
            date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
          let mm =
            date.getMinutes() < 10
              ? "0" + date.getMinutes()
              : date.getMinutes();
          var ss = date.getSeconds();
          let curDay =
            yyyy + "-" + MM + "-" + dd + "T" + HH + ":" + mm + ":" + ss;
          this.stop_time = curDay;
          this.tingzhilogdeposit = true;
          break;

        case "fc":
          this.$confirm("是否确定作废医嘱", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          }).then(() => {
            toVoidAdvice({
              hospital_id: this.id,
              id: arr,
            }).then((res) => {
              if (res.code == 200) {
                this.$message.success("成功作废");
                this.getAdviceList(this.id);
              } else {
                this.$message(res.message);
              }
            });
          });
          break;
        case "tjcy":
          this.changyonglogdeposit = true;
          this.changyong.extra_json = JSON.stringify(that.multipleSelection);
          break;
      }
    },
    doctorStopAdvice() {
      var arr = [];
      var if_bian = true;
      this.multipleSelection.forEach((res) => {
        arr.push(res.id);
        if (res.status != "草稿") {
          if_bian = false;
        }
      });
      console.log(this.stop_time);
      arr = arr.toString();
      doctorStopAdvice({
        hospital_id: this.id,
        ids: arr,
        action_type: 1,
        stop_time: this.stop_time.replace("T", " "),
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "停止成功",
            type: "success",
          });
          this.getAdviceList(this.id);
          this.tingzhilogdeposit = false;
        } else {
          this.$message(res.message);
        }
      });
    },

    changyonghead() {
      if (this.changyong.title == "") {
        this.$message({
          message: "标题不能为空",
        });
      } else {
        collectAdvice(this.changyong).then((res) => {
          console.log(res);

          if (res.code == 200) {
            this.$message({
              message: "提交成功",
              type: "success",
            });
          }
          this.$refs.logging2.getCollectAdvice();
          this.changyonglogdeposit = false;
        });
      }
    },
    //切换
    handleClick(tab, event) {
      if (this.activeName == "second") {
        this.getMemberMedicalList();
      } else if (this.activeName == "third") {
      }
    },
    handleClick2(tab, event) {
      // console.log(tab, event);
    },
    //病历
    getMemberMedicalList() {
      var that = this;
      getMemberMedicalList({ hospital_id: this.id }).then((res) => {
        that.binglilist = res.data;
      });
    },
    getDrugItem() {
      let d = {
        keyword: this.selectParams.keyword,
        page: this.selectParams.page,
        limit: this.selectParams.limit,
        source: 1,
      };

      getAdviceDrug(d).then((res) => {
        if (res.code == 200) {
          this.selectData.selectData1 = res.data.list;
          var data = this.selectData.selectData1;
          for (let i = 0; i < data.length; i++) {
            this.selectData.selectData1[i].typename = data[i].species.name;
          }
          this.selectParams.pageCount = res.data.count;
        }
      });
    },

    //获取诊断
    getDiseaseDict(e) {
      let d = {
        keyword: this.selectParams2.keyword,
        page: this.selectParams2.page,
        limit: this.selectParams2.limit,
      };
      getgetDiseaseDict(d)
        .then((res) => {
          let data = res.data.lists;
          console.log(data);
          this.selectData2.selectData1 = data;
          this.selectParams2.pageCount = res.data.count;
        })
        .catch((e) => { });
    },
    getDiseaseDict2(e) {
      let d = {
        keyword: this.selectParams2.keyword2,
        page: this.selectParams2.page2,
        limit: this.selectParams2.limit2,
      };
      getgetDiseaseDict(d)
        .then((res) => {
          let data = res.data.lists;
          console.log(data);
          this.selectData2.selectData1 = data;
          this.selectParams2.pageCount2 = res.data.count;
        })
        .catch((e) => { });
    },
    getAdviceFeeItem(arr) {
      if (arr[0]) {
        if (arr[0] == 1 || arr[0] == 9) {
          this.getDrugItem();
        } else if (arr[0] == 7) {
          let d = {
            page: this.selectParams.page,
            limit: this.selectParams.limit,
            keyword: this.selectParams.keyword,
          };
          console.log("1");
          shuyugetList(d).then((res) => {
            if (res.code == 200) {
              this.selectData.selectData1 = res.data.list;
              var data = this.selectData.selectData1;
              for (let i = 0; i < data.length; i++) {
                this.selectData.selectData1[i].name = data[i].title;
                this.selectData.selectData1[i].typename = "医嘱术语";
              }
              this.selectParams.pageCount = res.data.count;
            }
          });
        } else if (arr[0] == 11) {
          getCollectAdvice().then((res) => {
            console.log(res);
            this.selectData.selectData1 = res.data;
            this.selectParams.pageCount = res.data.length;
          });
        } else if (arr[0] == 12) {
          getServiceGroup().then((res) => {
            console.log(res);
            this.selectData.selectData1 = res.data;
            this.selectParams.pageCount = res.data.length;
          });
        } else if (arr[0] != 7 || arr[0] != 11 || arr[0] != 12) {
          console.log(this.selectParams.keyword);
          // var art = arr[0] == 8 ? 1 : arr[0] == 4 ? 2 : arr[0] == 6 ? 4 :arr[0] == 13 ? 6: "";
          let d = {
            // type: '1,2,4,6',
            page: this.selectParams.page,
            limit: this.selectParams.limit,
            keyword: this.selectParams.keyword,
          };

          getAdviceFee(d).then((res1) => {
            if (res1.code == 200) {
              this.selectData.selectData1 = res1.data.list;

              var data = this.selectData.selectData1;
              console.log(data);
              for (let i = 0; i < data.length; i++) {
                this.selectData.selectData1[i].type = data[i].type;
                this.selectData.selectData1[i].typename =
                  data[i].type == 1
                    ? "普通项目"
                    : data[i].type == 2
                      ? "检查"
                      : data[i].type == 3
                        ? "检验"
                        : data[i].type == 4
                          ? "治疗"
                          : data[i].type == 7
                            ? "医嘱术语"
                            : data[i].type == 6
                              ? "量表"
                              : "手术";
              }
              this.selectParams.pageCount = res1.data.count;
            }
          });
        }
      }
    },

    //获取数字字典
    getDict_dataDictIndex() {
      getdictIndex({ group_id: "47,12,36,6,60,61,69" }).then((res) => {
        let data = res.data;

        data.forEach((item, key) => {
          if (item.id == 47) {
            that.disu = item.items;
          } else if (item.id == 12) {
            that.xiyaojiaozhu = item.items;
          } else if (item.id == 36) {
            that.shoufeitype = item.items;
          } else if (item.id == 6) {
            that.yinshi = item.items;
          } else if (item.id == 61) {
            that.danwei = item.items;
          } else if (item.id == 60) {
            that.zhijidanwei = item.items;
          } else if (item.id == 69) {
            that.xiangmudanwei = item.items;
          }
        });
      });
    },

    getCommonGetPinci() {
      that["_API"].getCommonGetPinci().then((res) => {
        console.log(res.data);
        that.pinci = res.data;
      });
    },
    getDrug_channelGetList() {
      let t = this;

      t["_API"].getDrug_channelGetList().then((res) => {
        console.log(res);
        that.geiyao = res.data.list;
      });
    },
    zhenduanHospital() {
      this.$refs.rightZD.createAdvice();
    },
    createAdvice2(arr) {
      console.log(arr[0]);
      var d = {
        hospital_id: this.id,
        disease_info: [],
      };
      var is_up = false;
      if (arr[0]) {
        console.log(arr[0]);
        arr[0].forEach((res) => {
          if (res.diag_type != undefined) {
            d.disease_info.push({
              id: res.id,
              number: res.number,
              disease_id: res.disease_id,
              name: res.name,
              result_id: res.result_id,
              diagnostic_time: res.diagnostic_time,
              disease_time: res.disease_time,
              // is_contagion: res.is_contagion?1:2,
              // is_operation:res.is_operation?1:2,
              maindiag_flag: res.maindiag_flag ? 1 : 0,
              diag_type: res.diag_type,
              adm_cond_type: res.adm_cond_type,
              adm_cond: res.adm_cond,
              type: res.type == "入院诊断" ? 1 : res.type == "出院诊断" ? 2 : 3,
            });
          } else {
            this.$message("请选择诊断类别");
            is_up = true;
          }
        });
        if (is_up) {
          return false;
        } else {
          saveDiagonsis(d).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "提交成功",
                type: "success",
              });
            }
            this.zhenduanlogdeposit = false;
          });
        }
      }
    },
    cancelHospital() {
      this.$refs.rightCZ.createAdvice();
    },
    createAdvice(arr) {
      var that = this;
      console.log(arr);
      var data_t = {
        hospital_id: that.id,
        member_id: that.member_id,
        remark: arr[2],
        doctor_id: arr[3],
        save_btn: "1",
        drug: [],
        id: "",
      };
      if (arr[0].length != 0) {
        arr[0].forEach((res) => {
          data_t.drug.push({
            business_id: res.id,
            type: res.type,

            skin_test: res.is_skin_test ? "1" : "2",
            // 1西药2中药3检验4检查5手术6治疗
            start_time: res.start_time,
            // fill_no:res.fill_no,d
            dose: res.dose,
            // jiaozhu: res.usage_extra,
            usage: res.usage,
            used_frqu_id: res.each_dos,
            fee_category_name: res.fee_category_name,
            // used_frqu:res.each_dos,
            fee_category_id: res.fee_category_id,
            number: res.count,
            end_time: res.end_time,
            dose_base: res.dose_base,
            drip_speed: res.trans_speed,
            remark: res.remark,
            business_name: res.name,
            base_unit: res.base_unit,
            dose_unit: res.dose_unit,
            unit: res.base_unit,

            is_group: res.is_group,
            time_type: "2",
          });
        });
      }
      if (arr[1].length != 0) {
        arr[1].forEach((res) => {
          data_t.drug.push({
            business_id: res.id,
            type: res.type,

            skin_test: res.is_skin_test ? "1" : "2",
            // 1西药2中药3检验4检查5手术6治疗
            start_time: res.start_time,
            // fill_no:res.fill_no,d
            dose: res.dose,
            // jiaozhu: res.usage_extra,
            used_frqu_id: res.each_dos,
            fee_category_name: res.fee_category_name,
            // used_frqu:res.each_dos,
            fee_category_id: res.fee_category_id,
            number: res.count,
            end_time: res.end_time,
            usage: res.usage,
            dose_base: res.dose_base,
            base_unit: res.base_unit,
            drip_speed: res.trans_speed,
            dose_unit: res.dose_unit,
            remark: res.remark,
            business_name: res.name,
            unit: res.base_unit,
            is_group: res.is_group,
            time_type: "1",
          });
        });
      }
      if (this.yizhudeposit) {
        if (arr[0].length != 0) {
          data_t.drug[0].id = arr[0][0].id2;
          data_t.drug[0].start_time = arr[0][0].start_time.replace("T", " ");
        } else {
          data_t.drug[0].id = arr[1][0].id2;
          data_t.drug[0].start_time = arr[1][0].start_time.replace("T", " ");

          console.log(data_t.drug);
        }

        console.log(data_t);
        updateAdvice(data_t).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "修改成功",
              type: "success",
            });

            this.yizhudeposit = false;
            // that.canceldialogdeposit = false;
            this.getAdviceList(this.id);
          } else {
            this.$message({
              message: res.message,
              type: "warning",
            });
          }
        });
      } else {
        createAdvice(data_t).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: "开立成功",
              type: "success",
            });
            // that.canceldialogdeposit = false;
            this.$refs.rightCZ.cleardata();
            this.getAdviceList(this.id);
          } else {
            this.$message({
              message: res.message,
              type: "warning",
            });
          }
        });
      }
    },
    xiugai(row) {
      var art = JSON.parse(JSON.stringify(row));
      console.log(art);
      art.name = row.business_name;

      art.type = row.type;
      art.remark = row.remark;
      art.count = row.number;
      art.id2 = row.id;
      art.id = row.business_id;

      art.is_skin_test = row.skin_test == "皮试" ? true : false;
      //  if (row.fee_category_id<10) {
      //   row.fee_category_id='0'+ row.fee_category_id
      // }else{
      //    row.fee_category_id=row.fee_category_id
      // }
      art.base_unit = row.base_unit;
      art.base_unit = row.unit;

      art.each_dos = row.used_frqu.used_frqu_id
        ? art.used_frqu.used_frqu_id
        : 1;
      art.start_time = row.start_time.replace(" ", "T");
      this.dialogForm = art;
      console.log(this.dialogForm);
      this.yizhudeposit = true;
    },
    shouqi() {
      if (this.span1 == 6) {
        this.span1 = 1;
        this.span2 = 23;
      } else {
        this.span1 = 6;
        this.span2 = 18;
      }
    },
    xiugaiup() {
      var arr = [];

      if (this.dialogForm.time_type == "长期") {
        arr.push([]);
        arr.push([this.dialogForm]);
        arr.push(this.dialogForm.remark);
        arr.push(this.dialogForm.advice_doctor);
      } else {
        arr.push([this.dialogForm]);
        arr.push([]);
        arr.push(this.dialogForm.remark);
        arr.push(this.dialogForm.advice_doctor);
      }
      this.createAdvice(arr);
    },
    zongliang() {
      var pcnum = this.matching2(this.dialogForm.each_dos);

      var pcnum2 = parseInt(pcnum);
      var dose = parseInt(this.dialogForm.dose);
      var dose_base = parseInt(this.dialogForm.dose_base);
      console.log(pcnum2, dose_base, dose);
      this.dialogForm.count = Math.round((pcnum2 * dose) / dose_base);
    },
    matching2(arr) {
      var that = this;
      var art = "";
      //  console.log(art,that.thatF.pinci)
      for (var i in that.pinci) {
        if (that.pinci[i].id == arr) {
          art = that.pinci[i].number;
          console.log(art);
          return art;
        }
      }
    },
    datedifference(sDate1, sDate2) {
      //sDate1和sDate2是2006-12-18格式
      var dateSpan, tempDate, iDays;
      sDate1 = Date.parse(sDate1);
      sDate2 = Date.parse(sDate2);
      dateSpan = sDate2 - sDate1;
      dateSpan = Math.abs(dateSpan);
      iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
      return iDays;
    },
    //搜索
    onSubmit() {
      this.getAdviceList(this.id);
    },
    //获取医嘱列表
    getAdviceList(e) {
      var data = {
        hospital_id: e,
        time_type: this.tabIndex,
        keyword: this.keyword,
        status: this.statusIndex.toString(),
        time: this.datatime,
        advice_type: this.advice_type,

        limit: 1000,
      };
      getAdviceList(data).then((res) => {
        this.tableData1 = [];
        this.tableData2 = [];
        if (res.code == 200) {
          this.tableData = res.data.list;
          for (let i in this.tableData) {
            this.tableData[i].source =
              this.tableData[i].source == 1 ? "医生" : "护士";

            this.tableData[i].advice_type =
              this.tableData[i].advice_type == 1 ? "项目" : "药品";
            this.tableData[i].dose_unit2 =
              this.tableData[i].dose + "" + this.tableData[i].dose_unit;
            //  this.tableData[i].department_name2=this.tableData[i].department_name.split('/')[this.tableData[i].department_name.split('/').length-1]
            this.tableData[i].result2 =
              this.tableData[i].skin_result == 1
                ? "(-)"
                : this.tableData[i].skin_result == 2
                  ? "(+)"
                  : "";
            this.tableData[i].number2 =
              this.tableData[i].number + "" + this.tableData[i].unit;
            this.tableData[i].time_type =
              this.tableData[i].time_type == 1 ? "长期" : "临时";
            this.tableData[i].typename =
              this.tableData[i].type === 1
                ? "西药"
                : this.tableData[i].type === 2
                  ? "中药"
                  : this.tableData[i].type === 3
                    ? "检验"
                    : this.tableData[i].type === 4
                      ? "检查"
                      : this.tableData[i].type === 5
                        ? "手术"
                        : this.tableData[i].type === 10
                          ? "自带药"
                          : this.tableData[i].type === 11
                            ? "量表"
                            : this.tableData[i].type === 7
                              ? "医嘱术语"
                              : this.tableData[i].type === 8
                                ? "普通项目"
                                : this.tableData[i].type === 9
                                  ? "出院带药"
                                  : "治疗";
            this.tableData[i].advice_status =
              this.tableData[i].advice_status == 1 ? "待执行" : "已执行";
            this.tableData[i].skin_test =
              this.tableData[i].skin_test == 1 ? "皮试" : "继用";
            this.tableData[i].check_type =
              this.tableData[i].check_type == 1
                ? "通过"
                : this.tableData[i].check_type == 2
                  ? "未通过"
                  : "不通过";
            this.tableData[i].status =
              this.tableData[i].status == 1
                ? "草稿"
                : this.tableData[i].status == 2
                  ? "提交"
                  : this.tableData[i].status == 3
                    ? "校对"
                    : this.tableData[i].status == 4
                      ? "完成"
                      : this.tableData[i].status == 5
                        ? "待停止"
                        : this.tableData[i].status == 6
                          ? "已停止"
                          : "废除";

            //低速
            // this.tableData[i].drip_speed = this.matching(
            //   this.tableData[i].drip_speed,
            //   1
            // );
            // this.tableData[i].used_frqu = this.matching(
            //   this.tableData[i].used_frqu,
            //   2
            // );
            // this.tableData[i].usage = this.matching(this.tableData[i].usage, 3);

            // this.tableData[i].jiaozhu = this.matching(
            //   this.tableData[i].jiaozhu,
            //   4
            // );
          }
        }
      });
    },
    getMyMedicalSkill() {
      var data = {
        hospital_id: this.patientinfo.id,
      };
      getMyMedicalSkill(data).then((res) => {
        if (res.code == 200) {
          this.yijidata = res.data.list;
        }
      });
    },
    //设置饮食
    setFood() {
      that.fooddialogdeposit = true;
      // that.getdiet_list();
    },
    //诊断维护
    setzhenduan() {
      that.zhenduanlogdeposit = true;
    },
    setbiangeng() {
      this.drawer = true;
    },
    //设置饮食
    foodHospital() {
      var data_t = that.foodinfo;
      data_t.id = that.id;
      that.yinshi.map(function (value, i, array) {
        if (array[i].id == that.foodinfo.pid) {
          data_t.name = array[i].name;
        }
      });
      console.log(data_t);
      setFood(data_t)
        .then((res) => {
          // let data = res.data;
          // console.log(res);
          if (res.code == 200) {
            that.fooddialogdeposit = false;
          }
        })
        .catch((e) => { });
    },
    //匹配
    matching(arr, i) {
      var art = "";
      var that = this;
      switch (i) {
        case 1:
          for (var i in that.disu) {
            if (that.disu[i].id == arr) {
              art = that.disu[i].name;
            }
            return art;
          }

          break;

        case 2:
          for (var i in that.pinci) {
            if (that.pinci[i].id == parseInt(arr)) {
              art = that.pinci[i].name;
            }
            return art;
          }
          break;
        case 3:
          for (var i in that.geiyao) {
            if (that.geiyao[i].id == arr) {
              art = that.geiyao[i].name;
            }
            return art;
          }
          break;
        case 4:
          for (var i in that.xiyaojiaozhu) {
            if (that.xiyaojiaozhu[i].id == arr) {
              art = that.xiyaojiaozhu[i].name;
            }

            return art;
          }
          break;
      }
    },
    setchangyong() {
      this.changyonglog = true;
    },
    printAdvice() {
      var arr = [];
      that.multipleSelection.forEach((res) => {
        arr.push(res.id);
      });
      arr = arr.toString();
      var data = {
        hospital_id: this.patientinfo.id,
        ids: arr,
        type: this.tabIndex,
      };
      printAdvice(data).then((res) => {
        // this.yizhudata=
        this.yizhudata = JSON.stringify(res.data);
        if (this.tabIndex == "1") {
          const { href } = this.$router.resolve({
            path: "/workstation/yizhudan",
            query: { yizhudata: this.yizhudata },
          });
          window.open(href, "_blank");
        } else {
          const { href } = this.$router.resolve({
            path: "/workstation/linyizhudan",
            query: { yizhudata: this.yizhudata },
          });
          window.open(href, "_blank");
        }

        //  this.yizhudataVisible1=true

        console.log(res);
      });
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      //  ||columnIndex === 3||columnIndex === 13||columnIndex === 14||columnIndex === 12||columnIndex === 15
      if (columnIndex === 2) {
        if (
          this.tableData[rowIndex].is_group != null &&
          this.tableData[rowIndex].is_group != 0
        ) {
          var arr = [];
          for (let i = 0; i < this.tableData.length; i++) {
            if (this.tableData[i].is_group == row.is_group) {
              arr.push(i);
            }
            for (let i = 0; i < arr.length; i++) {
              if (i == 0) {
                this.tableData[arr[i]].id2 = "┌";
              } else if (i == arr.length - 1) {
                this.tableData[arr[arr.length - 1]].id2 = "└";
              } else {
                this.tableData[arr[i]].id2 = "|";
              }
            }
          }
        } else {
          //   if (rowIndex % 2 === 0) {
          // return {
          //   rowspan: 2,
          //   colspan: 1
          // }
          //  }else{
          //    return {
          //   rowspan: 0,
          //   colspan: 0
          // };
          //  }
        }
      }
    },
  },
  components: {
    ViewTitle,
    kailiyizhu,
    exect,
    TopManu,
    record,
    costRecord,
    infocrad,
    infocradNurse,
    zhenduan,
    caselist,
    compile,
    iframeDemo,
    logging,
    yizhudan,
    linyizhudan,
    Splitbed,
  },
};
</script>

<style lang='scss' >
.pen_count {
  display: flex;
  align-items: center;

  >div {
    font-weight: bold;

    font-size: 0.875rem;
    color: #606266;
    line-height: 2.5rem;
    padding: 0 0.75rem 0 0;

    >span {
      color: red;
    }
  }
}

.box {
  width: 100%;
  height: 100%;
  padding: 5px 20px;
}

.right-tabs2 {
  .right-tabs-flex2 {
    position: absolute;
    z-index: 900;
    right: 0px;
    padding: 0;
    margin: 0;
    text-align: center;
    line-height: 50px;
    list-style: none;
    margin-top: 10px;
    width: 80px;
    background-color: #fff;
    border: 1px solid #e5e5e5;

    li {
      padding: 0;
      margin: 0;
      width: 80px;
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #e5e5e5;
    }

    li:nth-child(1) {
      color: #dcdfe6;
    }

    li:nth-child(2) {
      color: #65da8a;
    }

    li:nth-child(3) {
      color: #79a5ec;
    }

    li:nth-child(4) {
      color: #e7bb6a;
    }

    li:nth-child(5) {
      color: #a8a493;
    }

    li:nth-child(6) {
      color: #e4899d;
    }

    li:nth-child(7) {
      color: #594ecfc4;
    }
  }

  div {
    padding: 10px 20px;
    background: #e5e5e5;
    color: #000;
    cursor: pointer;
    float: right;
    width: 100%;
    text-align: center;
  }

  // div:nth-child(1){
  //   border-top-left-radius: 10px;
  //   border-bottom-left-radius: 10px;
  // }
  // div:nth-child(4){
  //   border-top-right-radius: 10px;
  //   border-bottom-right-radius: 10px;
  // }
  display: flex;
  border-radius: 10px;
  width: 80px;
  float: right;
}

.dialog-text {
  margin-bottom: 8px;
}

// /deep/.el-table tbody tr:hover > td {
//   background: transparent !important;
// }
// .el-table .el-table__row:hover > td {
//   background-color: transparent !important;
// }

// .el-table__body >td.el-table__cell, .el-table__body tr.hover-row.el-table__row--striped.current-row>td.el-table__cell, .el-table__body tr.hover-row.el-table__row--striped>td.el-table__cell, .el-table__body tr.hover-row>td.el-table__cell{
//    background-color: transparent !important;
// }

.el-table .status-1 {
  background: #dcdfe6 // !important;
}

.el-table .status-2 {
  background: #65da8a // !important;
}

.el-table .status-3 {
  background: #79a5ec //  !important;
}

.el-table .status-4 {
  background: #e7bb6a //  !important;
}

.el-table .status-5 {
  background: #a8a493 // !important;
}

.el-table .status-6 {
  background: #e4899d // !important;
}

.el-table .status-7 {
  background: #867cf1 //  !important;
}

.el-table .success-row {
  background: #409eff // !important;
}
</style>
